package com.yt.ds.chapter4;

/**
 * @Author: lzf
 * @Date: 2020/7/31 09:55
 * @Description: 拓扑排序: 一幅有向无环图的拓扑排序即为所有顶点的逆后序排列
 */
public class Topological {
    private Iterable<Integer> order;

    public Topological(Digraph graph){
        DirectedCycle cycle = new DirectedCycle(graph);
        if(!cycle.hasCycle()){
            DepthFirstOrder dfs = new DepthFirstOrder(graph);
            order = dfs.reversePost();
        }
    }

    public Iterable<Integer> order(){
        return order;
    }

    /**
     * 描述：是有向无环图吗
     * @param
     * @return "boolean"
     * @date: 2020/7/31 10:07
     */
    public boolean isDAG(){
        return order != null;
    }
}
